package com.example.loginmvvm.base

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.example.loginmvvm.lifecycle.ILifecycleOwner
import com.example.loginmvvm.lifecycle.LifeState
import com.example.loginmvvm.lifecycle.LifecycleProvide

/*
 * class title: 
 * Author by RenChunLin, Email 18957806320@163.com, Date on 2021/4/19.
 * PS: Not easy to write code, please indicate.
 */
open class BaseFragment : Fragment(),ILifecycleOwner {

    val lifecycleProvide by lazy {
        LifecycleProvide()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        lifecycleProvide.makeLifeState(LifeState.CREATE)
    }

    override fun onStart() {
        super.onStart()
        lifecycleProvide.makeLifeState(LifeState.START)
    }

    override fun onResume() {
        super.onResume()
        lifecycleProvide.makeLifeState(LifeState.RESUME)
    }

    override fun onPause() {
        super.onPause()
        lifecycleProvide.makeLifeState(LifeState.PAUSE)
    }

    override fun onStop() {
        super.onStop()
        lifecycleProvide.makeLifeState(LifeState.STOP)
    }

    override fun onDestroy() {
        super.onDestroy()
        lifecycleProvide.makeLifeState(LifeState.DESTROY)
    }

    override fun getLifecycleProvider(): LifecycleProvide {
        return lifecycleProvide
    }
}